#include "led.h"

void LED_Init(void)
{
    RCC->APB2ENR |= RCC_APB2ENR_IOPBEN;
	
	GPIOB->CRL |= GPIO_CRL_MODE0;
	GPIOB->CRL &= ~GPIO_CRL_CNF0;
	
	GPIOB->CRL |= GPIO_CRL_MODE1;
	GPIOB->CRL &= ~GPIO_CRL_CNF1;

    LED_Off(LED1);
    LED_Off(LED2);
}

void LED_On(uint16_t led)
{
    GPIOB->ODR |= led;
}

void LED_Off(uint16_t led)
{
    GPIOB->ODR &= ~led;
}

void LED_Toggle(uint16_t led)
{
    if ((GPIOB->IDR & led) == 0)
    {
        LED_On(led);
    }
    else
    {
        LED_Off(led);
    }
    
}

void LED_OnAll(uint16_t leds[],uint16_t size)
{
    for (uint8_t i = 0; i < size; i++)
    {
        LED_On(leds[i]);
    }
}

void LED_OffAll(uint16_t leds[],uint16_t size)
{
    for (uint8_t i = 0; i < size; i++)
    {
        LED_Off(leds[i]);
    }
}